// https://leetcode.cn/problems/add-two-numbers/?favorite=2cktkvj
// Created by ade on 2022/12/14.
//

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */

struct ListNode {
    int val;
    ListNode *next;

    ListNode() : val(0), next(nullptr) {}

    ListNode(int x) : val(x), next(nullptr) {}

    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {
        ListNode *res = new ListNode;
        ListNode *index = res;
        int flag = 0;
        while (l1 || l2 || flag) {
            ListNode *tmp = new ListNode;
            if (l1) tmp->val = l1->val;
            if (l2) tmp->val = l2->val;
            tmp->val += flag;
            if (tmp->val >= 10) {
                flag = 1;
            } else {
                flag = 0;
            }
            tmp->val %= 10;
            index->next = tmp;
            index = index->next;
            if (l1) l1 = l1->next;
            if (l2) l2 = l2->next;
        }
        return res->next;
    }
};

#include "stdio.h"

#define SWAP(a,b) {(a) = (a)+(b); (b) = (a) - (b); (a) = (a) - (b); }

int main(){
    unsigned char i = 1;
    int n = 256;
    while(n--){
        i++;
    }
    printf("i=%d",i);

    return 0;
}

